﻿<!doctype html>
<html>
<head>
    <meta charset="utf-8">

    <title>定时器-秒表练习</title>
    <style>
    </style>
    <script>
        function toDou(n) {
            if (n < 10) {
                return '0' + n;
            } else {
                return n;
            }
        }
        window.onload = function () {
            var oT = document.getElementById('t1');
            var oBtn = document.getElementById('btn1');
            var count = 0;

            oBtn.onclick = function () {
                function secClock() {
                    count++;
                    oT.value = toDou(parseInt(count / 60)) + '分' + toDou(count % 60) + '秒';
                }

                secClock();  //先调用一次,解决卡的问题
                setInterval(secClock, 1000);
            }
        }
    </script>
</head>

<body>
<input type="text" value="" id="t1">
<input type="button" value="计时" id="btn1">
</body>
</html>
